<template>
	<view class="container">
		<view class="bg">
			<image src='/static/my-bg.png'></image>
		</view>
		<view class="wrap">
			<view class="user-con">
				<view class="user">我的</view>
				<view class="uid">ID:{{userInfo.user_number}}</view>
				<view class="copy" @tap='copy(userInfo.user_number)'>复制</view>
			</view>
			<view class="contribution-wrap">
				<view class="title-wrap">
					<view class="title">我的贡献值</view>
					<view class="record" @tap="toPage('/pages/recharge-record/recharge-record')">充值记录</view>
				</view>
				<view class="num">{{userInfo.contribution ? userInfo.contribution : 0}}</view>
				<view class="btn-wrap">
					<view class="btn btn1 line-center" @tap="toPage('/pages/transfer/transfer')">转赠</view>
					<view class="btn btn2 line-center" @tap="toPage('/pages/recharge/recharge')">充值</view>
				</view>
			</view>
			<view class="order-wrap">
				<view class="title-wrap">
					<view class="title">订单管理</view>
					<view class="all" @tap='toPage("/pages/my-order/my-order?index=0")'>查看全部<uni-icons type="right" color='#979797' size="10"></uni-icons></view>
				</view>
				<view class="grid-wrap">
					<view class="grid-item" v-for='(item,index) in orderList' @tap='toPage(item.path)'>
						<image :src='item.icon'></image>
						<view class="text">{{item.text}}</view>
					</view>
				</view>
			</view>
			<view class="tool-wrap">
				<view class="tool-item" v-for="(item,index) in tooList" @tap='toPage(item.path,item.id)'>
					<image :src='item.icon'></image>
					<view class="text">{{item.text}}</view>
					<uni-icons type="right" color="#999999"></uni-icons>
				</view>
			</view>
		</view>
		<modal :showModal="showModal">
			<view class="transfer-modal animated"  :class="[showModal ? 'zoomIn':'zoomOut']">
				<view class="transfer-con">
					<view class="title">温馨提示</view>
					<view class="tip">确认退出登录吗？</view>
					<button class="transfer-btn line-center" :disabled="isDisabled" :loading="isDisabled" @tap='loginOut'>确认并退出</button>
				</view>
				<uni-icons type="close" color="#fff" size="40" @tap="close"></uni-icons>
			</view>
		</modal>
		<contact-modal :contactObj='contactObj' ref='contactModal'></contact-modal>
	</view>
</template>

<script>
	const app = getApp()
	import modal from '../../components/modal/modal.vue';
	import contactModal from '../../components/contact-modal/contact-modal.vue';
	export default {
		components: {
			contactModal
		},
		data() {
			return {
				showModal:false,
				isDisabled:false,
				userInfo: {},
				orderList: [{
						icon: '/static/dailingqu.png',
						text: '待领取',
						id: 1,
						path:'/pages/my-order/my-order?index=0'
					},
					{
						icon: '/static/daiqiantan.png',
						text: '待洽谈',
						id: 2,
						path:'/pages/my-order/my-order?index=1'
					},
					{
						icon: '/static/qiantanzhong.png',
						text: '洽谈中',
						id: 3,
						path:'/pages/my-order/my-order?index=2'
					},
					{
						icon: '/static/weiwancheng.png',
						text: '未完成',
						id: 4,
						path:'/pages/my-order/my-order?index=3'
					},
					{
						icon: '/static/yiwancheng.png',
						text: '已完成',
						id: 5,
						path:'/pages/my-order/my-order?index=4'
					}
				],
				tooList: [{
						icon: '/static/zhanghao.png',
						text: '账号管理',
						id: 1,
						path:'/pages/ali-account/ali-account'
					},
					{
						icon: '/static/pingtai.png',
						text: '平台协议',
						id: 2,
						path:'/pages/agreement/agreement'
					},
					{
						icon: '/static/concat.png',
						text: '联系客服',
						id: 3,
					},
					{
						icon: '/static/tuichu.png',
						text: '退出登录',
						id: 5,
					}
				],
				contactObj:{}
			};
		},
		onLoad() {

		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				let that = this;
				app.globalRequest({
					api: app.getApi().user.getUserInfo,
				}).then(res => {
					if (res.code == 0) {
						// res.data.mobile = encryptPhone(res.data.mobile)
						that.userInfo = res.data;
					} else if (res.code == 101) {
						that.token = ''
					}
				}).catch(err => {

				})
			},
			copy(e) {
				uni.setClipboardData({
					data: e, // e是你要保存的内容
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			},
			clearLogin(){
				uni.removeStorageSync('H5-TOKEN');
				uni.reLaunch({
					url:'/pages/login/login'
				})
			},
			loginOut(){
				this.isDisabled = true;
				app.globalRequest({
					api:app.getApi().loginApi.loginOut
				}).then(res=>{
					if(res.code == 0){
						this.isDisabled = false;
						this.clearLogin();
					}else{
						this.isDisabled = false;
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
					}
				})
			},
			toPage(path,type) {
				let that = this;
				if(type == 5){
					this.showModal = true;
					return;
				}
				if(type == 3){
					/* app.globalRequest({
						api: app.getApi().user.customer,
					}).then(res => {
						if (res.code == 0) {
							this.$refs.contactModal.show();
							this.contactObj = res.data;
						}
					}) */
					
					app.getCustomer()
					return;
				}
				uni.navigateTo({
					url: path
				})
			},
			close(){
				this.showModal = false;
			}
		}
	}
</script>
<style>
	page {
		width: 100%;
		height: 100%;
		background: #F5F7F9;
	}
</style>
<style lang="scss" scoped>
	.container {
		width: 100%;
	}

	.bg {
		width: 100%;
		height: 550rpx;
		position: absolute;
		left: 0;
		top: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.wrap {
		position: relative;
		z-index: 2;
	}

	.user-con {
		display: flex;
		align-items: center;
		padding: 180rpx 48rpx 0;

		.user {
			font-size: 48rpx;
		}

		.uid {
			font-size: 28rpx;
			margin-left: 20rpx;
		}

		.copy {
			font-size: 20rpx;
			color: #8E8E8E;
			margin-left: 16rpx;
		}
	}

	.contribution-wrap {
		margin: 30rpx 24rpx;
		padding: 36rpx 24rpx 40rpx;
		background: #FFFFFF;
		border-radius: 16rpx;

		.title-wrap {
			display: flex;
			align-items: center;
			justify-content: space-between;
			line-height: 40rpx;

			.title {
				font-size: 28rpx;
			}

			.record {
				font-size: 24rpx;
			}
		}

		.num {
			font-family: 'DIN-BOLD';
			font-size: 72rpx;
		}

		.btn-wrap {
			padding: 0 50rpx;
			display: flex;
			justify-content: space-between;
			margin-top: 28rpx;

			.btn {
				width: 260rpx;
				height: 72rpx;
				border-radius: 36rpx;
			}

			.btn1 {
				border: 2rpx solid #000000;
				box-sizing: border-box;
			}

			.btn2 {
				background: #000000;
				color: #fff;
			}
		}
	}

	.order-wrap {
		width: 702rpx;
		height: 228rpx;
		margin: 24rpx auto 0;
		background: url(@/static/order-bg.png) no-repeat;
		background-size: 100% 100%;
		padding: 28rpx 24rpx 20rpx;
		box-sizing: border-box;

		.title-wrap {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.title {
				font-weight: bold;
			}

			.all {
				font-size: 22rpx;
				color: #979797;
				display: flex;
				align-items: center;
			}
		}

		.grid-wrap {
			display: grid;
			grid-template-columns: repeat(5, 1fr);
			margin-top: 52rpx;

			.grid-item {
				image {
					width: 33rpx;
					height: 33rpx;
					margin: auto;
					display: block;
				}

				.text {
					font-size: 24rpx;
					line-height: 40rpx;
					text-align: center;
					padding-top:22rpx
				}
			}
		}
	}

	.tool-wrap {
		margin: 24rpx 24rpx;
		background: #fff;
		border-radius: 16rpx;

		.tool-item {
			height: 104rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			border-bottom: 2rpx solid #f2f2f2;

			image {
				width: 40rpx;
				height: 40rpx;
			}

			.text {
				font-size: 26rpx;
				flex: 1;
				margin-left: 20rpx;
			}
		}
	}
	
</style>